<?php
/**
 */

define("CACHE_PREFIX_JUBAO_UID","jubao_uid_");

class db_fanlaji_jubao_uid extends db_base {
    
	var $table_name = "fanlaji_jubao_uid";
	
	function db_fanlaji_jubao_uid()
	{
		parent::db_base();
	}
	
	
	
	/**
	 * 前台取单条信息
	 * @param $uid
	 */
	function get_list_by_uid($p=1,$pcount=10,$uid,$laji_have_del="")
	{
		if(!$uid)
		{
			return false;
		}
		
		$mc = mem_cache::get_instance();
		$key = CACHE_PREFIX_JUBAO_UID."-get_list_by_uid-{$uid}-{$laji_have_del}";
		
		$where_array = array();
		$where_array[] = " uid = {$uid} ";
		if(strlen($laji_have_del)>0 )$where_array[] = " laji_have_del = {$laji_have_del} ";
		
		$where = join(" and ",$where_array);
		
		
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$content = $this->get_alllist($this->table_name,$p,$pcount,"id desc",$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content;
		
	}
	
	function get_count_by_uid($uid,$laji_have_del="")
	{
		if(!$uid)
		{
			return false;
		}
		
		$mc = mem_cache::get_instance();
		$key = CACHE_PREFIX_JUBAO_UID."-get_count_by_uid-{$uid}-{$laji_have_del}";
		
		$where_array = array();
		$where_array[] = " uid = {$uid} ";
		if(strlen($laji_have_del)>0 )$where_array[] = " laji_have_del = {$laji_have_del} ";
		
		$where = join(" and ",$where_array);
		
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$content = $this->get_listcount($this->table_name,$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content[0];
		
	}
	
	function get_count_by_laji_uid_no_cache($laji_uid)
	{
		if(!$laji_uid)
		{
			return false;
		}
		
		$where_array = array();
		$where_array[] = "laji_uid = {$laji_uid} ";
		
		$where = join(" and ",$where_array);
		$content = $this->get_listcount($this->table_name,$where);
		
		
		return $content[0];
		
	}
	
	/**
	 * 用户注册
	 * @param $user_name
	 * @param $password
	 */
	function insert_fanlaji_jubao_uid($uid,$user_nickname,$laji_uid,$laji_nickname)
	{
		// 插入数据
		$ary = array();

		$ary["uid"] = $uid;
		$ary["user_nickname"] = $user_nickname;
		$ary["laji_uid"] = $laji_uid;
		$ary["laji_nickname"] = $laji_nickname;
		

		$ary["create_time"] = Date::get_date_time();
		$ary["create_data"] = Date::get_date();
		$ary["create_ip"] = IP::get_client_ip_long();
		$ary["status"] = 1;
		
		$ret = $this->insert($this->table_name, $ary);
		if ($ret)
		{
			/*$memcache = mem_cache::get_instance();
			$memcache->delete($key);*/
		}
		else
		{
			return false;
		}


		return $this->get_lastinsertid();
	}
	
	
	function update_fanlaji_jubao_uid_by_laji_uid($laji_uid,$laji_have_del="")
	{
		// 插入数据
		$ary = array();

		if(strlen($laji_have_del)>0)$ary["laji_have_del"] = $laji_have_del;
		if($laji_have_del == 1)
		{
			$ary["del_time"] = Date::get_date_time();
		}
		
		
		$where = "laji_uid = {$laji_uid}";
		$ret = $this->update($this->table_name, $ary,$where);
		if ($ret)
		{
			/*$memcache = mem_cache::get_instance();
			$memcache->delete($key);*/
		}
		else
		{
			return false;
		}


		return $this->get_lastinsertid();
	}
	
	
###########################

	
	
	
	/**
	 * cron 获取food_tag
	 */
	function admin_get_count_by_search($status="")
	{
		$where= array();
		if(strlen($status) > 0)
		{
			$status = intval($status);
			$where[] = "status = {$status}";
		}
		
		
		$where= join(",",$where);
		
		$data = $this->get_listcount($this->table_name, $where);
		
		return $data;
	}
	
	
	/*
	 * cron获取topic_lisy
	 */
	function admin_get_list_by_search($status="",$p=1,$pcount=10)
	{
		$where= array();
		if(strlen($status) > 0)
		{
			$status = intval($status);
			$where[] = "status = {$status}";
		}
		
		$where= join(",",$where);
		
		$p = intval($p);
		$pcount = intval($pcount);
		
		
		$data = $this->get_alllist($this->table_name,$p,$pcount,"create_time desc",$where);
		
		return $data;
	}
}



